/**
 * @author LKQ
 * @date 2021/12/28 22:15
 * @description
 */
public class Solution {
    public static void main(String[] args) {
        Solution solution = new Solution();
        int[] flowerbed = {0, 0, 1, 0, 0};
        System.out.println(solution.canPlaceFlowers(flowerbed, 1));
    }

    public boolean canPlaceFlowers(int[] flowerbed, int n) {
        int m = flowerbed.length;
        for (int i = 0; i < m; i++) {
            // 预处理
            if (i == 0 && flowerbed[i] == 1 && i+1 < m) {
                flowerbed[i+1]--;
            }else if (i == m - 1 && flowerbed[i] == 1 && i - 1 >= 0) {
                flowerbed[i-1]--;
            }else if (flowerbed[i] == 1 && i + 1 < m) {
                flowerbed[i-1]--;
                flowerbed[i+1]--;
            }
        }
        for (int i = 0; i < m; i++) {
            if (flowerbed[i] == 0) {
                n--;
                i++;
            }
        }
        return n <= 0;
    }
}
